package zara
import java.security.*

class HelperService {

    static transactional = true

    def hashBase64(str) {
         String ret="";
         try {
            //Hash算法
           MessageDigest sha = MessageDigest.getInstance("SHA-1");
           sha.update(str.getBytes());  
           ret=new sun.misc.BASE64Encoder().encode(sha.digest());
         }
         catch (Exception e) {
           System.out.print(e.getMessage());
         }
         return ret;
    } 
    // 将加密的再次加密
    def reEncode(str){
        def sources = "abcdefghijklmnopqrstuvwxyz/=ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
        def newsources = "efghijklvwmnopstux/qrabcdyzBHIJKCDEFXGLMN=OSTPZRUVWAYQ3679124805"
        def newstr = ""
        str.each{
            //println "each"+it
            newstr = newstr+newsources[sources.indexOf(it)]
        }
        return newstr
    }

    // 将加密的进行解密
    def reDecode(str){
        def sources = "abcdefghijklmnopqrstuvwxyz/=ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
        def newsources = "efghijklvwmnopstux/qrabcdyzBHIJKCDEFXGLMN=OSTPZRUVWAYQ3679124805"
        def newstr = ""
        str.each{
            //println "each"+it
            newstr = newstr+sources[newsources.indexOf(it)]
        }
        return newstr
    }
}
